﻿@model FileUploader

@{ 
	Html.AddScriptParts("~/bundles/fileupload");

	if (!Model.Name.HasValue())
	{
		Model.Name = "upload-" + CommonHelper.GenerateRandomInteger();
	}

	if (!Model.HtmlAttributes.ContainsKey("id"))
	{
		Model.Id = Model.Name;
	}
}

<div @Html.Attrs(Model.HtmlAttributes)>
	<!-- The global progress information -->
	<div class="fileupload-progress fade">
		<!-- The global progress bar -->
		<div class="progress">
			<div class="progress-bar" role="progressbar" style="width: 0%" aria-valuemin="0" aria-valuemax="100"></div>
		</div>

		@*<div class="progress-extended fs-xs text-muted text-truncate">&nbsp;</div>*@
	</div>

	<div class="fileupload-buttons">
		<button class="btn btn-danger remove@(Model.Compact ? " btn-sm" : "")" @Html.Attr("style", "display: none", !Model.ShowRemoveButton)>
			<span>@Model.RemoveText</span>
		</button>

		<span class="btn btn-@(Model.ButtonOutlineStyle ? "outline-" : "")@Model.ButtonStyle.ToString().ToLower() fileinput-button@(Model.Compact ? " btn-sm" : "")">
			@if (Model.IconCssClass.HasValue())
			{
				<i class="@Model.IconCssClass"></i>
			}
			<span>@Model.UploadText</span>
			<input type="file" id="@(Model.Id)-file" name="@(Model.Id)-file" />
		</span>

		<button class="btn btn-outline-secondary cancel@(Model.Compact ? " btn-sm" : "")" style="display: none">
			<span>@Model.CancelText</span>
		</button>
	</div>
</div>


<script data-origin="FileUploader">
	$(function () {
		$('#@Model.Id').fileUploadWrapper({
			onUploading: @Html.Raw(Model.OnUploadingHandlerName.HasValue() ? Model.OnUploadingHandlerName : "null"),
			onUploadCompleted: @Html.Raw(Model.OnUploadCompletedHandlerName.HasValue() ? Model.OnUploadCompletedHandlerName : "null"),
			onAborted: @Html.Raw(Model.OnAbortedHandlerName.HasValue() ? Model.OnAbortedHandlerName : "null"),
			onError: @Html.Raw(Model.OnErrorHandlerName.HasValue() ? Model.OnErrorHandlerName : "null"),
			onFileRemove: @Html.Raw(Model.OnFileRemoveHandlerName.HasValue() ? Model.OnFileRemoveHandlerName : "null"),
			onCompleted: @Html.Raw(Model.OnCompletedHandlerName.HasValue() ? Model.OnCompletedHandlerName : "null")
		});
    });
</script>
